package ${setApiPackageName};

import com.allen.app.common.domain.R;
import com.allen.app.common.BaseController;
import ${setDomainPackageName}.${DOMAIN_CLASSNAME};
import ${setServicePackageName}.${SERVICE_CLASSNAME};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ${pagingResultDto};
import lombok.AllArgsConstructor;

/**
 * Description:${tableAnnotation}接口类
 * @author ${author}
 * @date ${date}
 */
@Api(description = "${tableAnnotation}接口")
@RestController
@AllArgsConstructor
@RequestMapping("/${tableRequestPath}")
public class ${API_CLASSNAME} extends BaseController {

    private final ${SERVICE_CLASSNAME} ${service_classname};
<#--    @Autowired-->
<#--    public ${API_CLASSNAME}(${SERVICE_CLASSNAME} ${service_classname}) {-->
<#--        this.${service_classname} = ${service_classname};-->
<#--    }-->

    @PostMapping
    @ApiOperation(value = "添加${tableAnnotation}")
    public R<Integer> add(@RequestBody ${DOMAIN_CLASSNAME} ${domain_classname}) {

        return ok(${service_classname}.create${DOMAIN_CLASSNAME}(${domain_classname}));
    }

    @PutMapping
    @ApiOperation(value = "根据id更新${tableAnnotation}")
    public R<Integer> edit(@RequestBody ${DOMAIN_CLASSNAME} ${domain_classname}) {

        return ok(${service_classname}.update${DOMAIN_CLASSNAME}ById(${domain_classname}));
    }

    @DeleteMapping
    @ApiOperation(value = "根据ids删除${tableAnnotation}")
    @ApiImplicitParam(paramType = "path", name = "ids", value = "要删除${tableAnnotation}的ids,逗号分割", required = true, dataType = "String")
    public R<Integer> remove(@PathVariable("ids") String ids) {

        return ok(${service_classname}.delete${DOMAIN_CLASSNAME}ByIds(ids));
    }

    @ApiOperation(value = "根据id查询${tableAnnotation}")
    @GetMapping("/{id}")
    public R<${DOMAIN_CLASSNAME}> getInfo(@PathVariable("id") ${primaryKeyModtype} id) {

        return ok(${service_classname}.select${DOMAIN_CLASSNAME}ById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询${tableAnnotation}列表")
    public R<PageResult<${DOMAIN_CLASSNAME}>> list(${DOMAIN_CLASSNAME} ${domain_classname}){
        startPage();
        return ok(
            PageResult.of(
                ${service_classname}.select${DOMAIN_CLASSNAME}List(${domain_classname})
            )
        );
    }
}
